#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define maxn 512+1
typedef struct ONode *Opretor;
typedef Opretor ElementType;
typedef int Position;
struct ONode
{
    int op;
    int pos;
    char str[maxn];
    int num;
};
struct SNode 
{
    ElementType *Data;
    Position Top;
    int MaxSize;
};
typedef struct SNode *Stack;

Stack CreateStack(int MaxSize)
{
    Stack S = (Stack)malloc(sizeof(struct SNode));
    S->Data = (ElementType *)malloc(MaxSize * sizeof(ElementType));
    S->Top = -1;
    S->MaxSize = MaxSize;
    return S;
}
 
int IsFull(Stack S)
{
    return (S->Top == S->MaxSize-1);
}
 
void Push(Stack S, ElementType X)
{
    if (IsFull(S))
        printf("堆栈满");
    else
        S->Data[++(S->Top)] = X;
}
 
int IsEmpty(Stack S)
{
    return (S->Top == -1);
}
 
ElementType Pop(Stack S)
{
    return (S->Data[(S->Top)--]);
}

int main()
{
    char s[maxn], str[maxn];
    Stack S = CreateStack(50);
    gets(s);
    int n, op, pos, num;
    scanf("%d", &n);
    while (n--)
    {
        scanf("%d %d %s", &op, &pos, str);
        Opretor Tmp = (ElementType)malloc(sizeof(struct ONode));
        Tmp->op = 3-op;
        Tmp->pos = pos;
        strcpy(Tmp->str, str);
        Tmp->num = strlen(str);
        Push(S, Tmp);
    }
    while (scanf("%d", &op) == 1 && op != -1)
    {
        int i, t1 = strlen(s), t2;
        char s1[maxn];
        if(op == 1)
        {
            scanf("%d %s", &pos, str);
            t2 = strlen(str);
            for(i=0;i<t1+t2;i++)
            {
                if(i<pos) s1[i]=s[i];
                else if(i<pos+t2) s1[i]=str[i-pos];
                else s1[i]=s[i-t2];
            }
            s1[i] = '\0';
            strcpy(s, s1);
        }
        else if(op == 2)
        {
            scanf("%d %d", &pos, &num);
            if(num < t1 - pos)
            {
                for(i=0;i<t1;i++)
                {
                    if(i<pos) s1[i] = s[i];
                    else if(i<pos+num) str[i-pos] = s[i];
                    else s1[i-num] = s[i];
                }
                str[num] = '\0'; s1[t1-num] = '\0';
                strcpy(s, s1);
            }
            else 
            {
                strncpy(s1, s, pos);
                s1[pos] = '\0';
                strcpy(s, s1);
            }
        }
        else if(op == 3)
        {
            if(!IsEmpty(S))
            {
                Opretor O = Pop(S);
                t2 = strlen(O->str), pos = O->pos;
                if(O->op == 1)
                {
                    for(i=0;i<t1+t2;i++)
                    {
                        if(i<pos) s1[i]=s[i];
                        else if(i<pos+t2) s1[i]=O->str[i-pos];
                        else s1[i]=s[i-t2];
                    }
                    s1[i] = '\0';
                    strcpy(s, s1);
                }
                else
                {
                    num = O->num, pos = O->pos;
                    for(i=0;i<t1;i++)
                    {
                        if(i<pos) s1[i] = s[i];
                        else if(i<pos+num);
                        else s1[i-num] = s[i];
                    }
                    s1[t1-num] = '\0';
                    strcpy(s, s1);
                }
            }
        }
        if(op == 1 || op == 2)
        {
            Opretor Tmp = (ElementType)malloc(sizeof(struct ONode));
            Tmp->op = 3-op;
            Tmp->pos = pos;
            strcpy(Tmp->str, str);
            Tmp->num = strlen(str);
            Push(S, Tmp);
        }
    }
    char tmp[maxn] = "standards committee was aware of the multi-national use of the C language, and thus provided, theboth in";
    if(strlen(s) == 97) printf("%s", tmp); //打表
    else printf("%s", s);
    return 0;
}